package com.alpha.tests;

import static org.junit.Assert.assertEquals;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.alpha.bom.Exam;
import com.alpha.bom.Professor;
import com.alpha.bom.RealExam;
import com.alpha.bom.Student;

public class ProfessorTest {
	private Professor professor;
	private Student student;
	private Exam exam;
	
	@Before
	public void setUp() throws Exception {
		professor = new Professor();
		student = new Student(1);
		exam = new RealExam(1);
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testAddStudentStudent() {
		assertEquals("Adding student", student, professor.addStudent(student));
		assertEquals("Adding existing student", null, professor.addStudent(student));
	}

	@Test
	public void testAddStudentInt() {
		assertEquals("Adding student", student, professor.addStudent(student.getUserId()));
		assertEquals("Adding existing student", null, professor.addStudent(1));
	}

	@Test
	public void testAddExam() {
		assertEquals("Adding exam", exam, professor.addExam(exam));
		assertEquals("Adding existing exam", null, professor.addExam(exam));
	}
	
	@Test
	public void testSearchStudent() {
		professor.addStudent(student);
		assertEquals("Searching for student", student.getUserId(), professor.searchStudent(1).getUserId());
		assertEquals("Searching for student not in the class list", null, professor.searchStudent(2));
	}
	
	@Test
	public void testDeactivateStudentStudent() {
		professor.addStudent(student);
		assertEquals("Deactivating student", true, professor.deactivateStudent(student));
		assertEquals("Checking student's status", false, professor.searchStudent(1).isActivated());
		assertEquals("Deactivating student not in class list", false, professor.deactivateStudent(new Student(2)));
	}

	@Test
	public void testDeactivateStudentInt() {
		professor.addStudent(student);
		assertEquals("Deactivating student", true, professor.deactivateStudent(student.getUserId()));
		assertEquals("Checking student's status", false, professor.searchStudent(student.getUserId()).isActivated());
		assertEquals("Deactivating student not in class list", false, professor.deactivateStudent(2));
	}

	@Test
	public void testLockExamExam() {
		professor.addExam(exam);
		assertEquals("Locking exam", true, professor.lockExam(exam));
		assertEquals("Checking exam's status", true, ((RealExam) exam).isLocked());
		assertEquals("Locking exam not in the list", false, professor.lockExam(new RealExam(2)));
	}

	@Test
	public void testLockExamInt() {
		professor.addExam(exam);
		assertEquals("Locking exam", true, professor.lockExam(exam.getExamId()));
		assertEquals("Checking exam's status", true, ((RealExam) exam).isLocked());
		assertEquals("Locking exam not in the list", false, professor.lockExam(2));
	}

	@Test
	public void testUnlockExamExam() {
		professor.addExam(exam);
		assertEquals("Locking exam", true, professor.unlockExam(exam));
		assertEquals("Checking exam's status", false, ((RealExam) exam).isLocked());
		assertEquals("Locking exam not in the list", false, professor.unlockExam(new RealExam(2)));
	}

	@Test
	public void testUnlockExamInt() {
		professor.addExam(exam);
		assertEquals("Locking exam", true, professor.unlockExam(exam.getExamId()));
		assertEquals("Checking exam's status", false, ((RealExam) exam).isLocked());
		assertEquals("Locking exam not in the list", false, professor.unlockExam(2));
	}
}
